﻿using Autofac;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Reflection;
using Module = Autofac.Module;

namespace IntelligentAgriculture.WebAPI
{
    /// <summary>
    /// Autofac注册服务类
    /// </summary>
    public class AutofacModuleRegister : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterAssemblyTypes(
                    Assembly.Load("IntelligentAgriculture.Services")
                    , Assembly.Load("IntelligentAgriculture.Contracts")
                )
            .Where(a => a.Name.EndsWith("Service")).AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(
                    Assembly.Load("IntelligentAgriculture.Domain")
                )
                .Where(a => a.Name.EndsWith("Repository")).AsImplementedInterfaces();

            builder.RegisterType<TokenService>();
        }
    }
}
